﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using PPI.Client.Utils;
using PPI.Entities;
using PPI.Entities.Inspections;
using PPI.Entities.Lookup;
using PPI.Entities.Polygon;

namespace PPI
{
    public partial class frmMaps : frmBase
    {
        public frmMaps()
        {
            InitializeComponent();
            base.MenuMain.Visible = false;
            this.FormSize = FormSizes.Large;
            
            this.ctrlGpsFilter.LoadList();
            this.ctrlGpsInspectionFilters.LoadList();
            this.ctrlInspectionFilter.LoadList();
        }

        public void LoadMaps(List<EUtility_Polygon> polygons)
        {
            try
            {
                selectMaps1.ClearMaps();
                selectMaps1.LoadMaps(polygons);

            }
            catch (Exception ex)
            {
                RegisterError.SaveError(ex);
            }
        }

        public List<EUtility_Polygon> GetSelectedMaps()
        {
            return selectMaps1.GetSelectedMaps();
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.None;
            this.Close();
        }

        private void frmMaps_Load(object sender, EventArgs e)
        {
            this.ctrlGpsInspectionFilters.ClearSelectedItems();
            this.ctrlGpsFilter.ClearSelectedItems();
            this.ctrlInspectionFilter.ClearSelectedItems();
            HidePanels();
            panelMaps.Visible = true;
            panelMaps.Dock = DockStyle.Fill;
        }


        public List<EVendor> GetSelectedVendors()
        {
            
            return ctrlGpsInspectionFilters.SelectedVendors();
        }

        public List<EVendor_Contact> GetSelectedContacts()
        {
            
            return ctrlGpsInspectionFilters.SelectedContacts();
        }

        public List<EVendor_Project> GetSelectedProjects()
        {
            
            return ctrlGpsInspectionFilters.SelectedProjects();

        }

        public List<EVendor_Visit_Type> GetSelectedVisitTypes()
        {
            return ctrlGpsFilter.SelectedVisitTypes();
        }

        public List<EXMissionStructures_TopType> GetSelectedTopTypes()
        {
            return ctrlGpsFilter.SelectedToptypes();
        }

        public List<EXMissionStructures_PoleClass> GetSelectedPoleClasses()
        {
            return ctrlGpsFilter.SelectedClasses();
        }

        public List<EXMissionStructures_PoleSpecies> GetSelectedPoleSpecies()
        {
            return ctrlGpsFilter.SelectedSpecies();
        }

        public List<EXMissionStructures_PoleTreatment> GetSelectedPoleTreatments()
        {
            return ctrlGpsFilter.SelectedTreatments();
        }

        public List<Int32> GetSelectedPoleYears()
        {
            return ctrlGpsFilter.SelectedYears();
        }

        public List<EResultType> GetSelectedResultTypes()
        {
            return ctrlInspectionFilter.SelectedInspectionResults();
        }

        public List<EInspectionTypes> GetSelectedInspectionTypes()
        {
            return ctrlInspectionFilter.SelectedInspectionTypes();
        }

        public bool ShowVisits
        {
            get { return chkShowVisit.Checked; }
            set
            {

                chkShowVisit.Checked = value;
                chkShowVisit.Enabled = value;
            }
        }

        public bool ShowAssets
        {
            get { return chkShowAsset.Checked; }
            set { chkShowAsset.Checked = value; }
        }

        public bool ShowInspectionVisits
        {
            set
            {
                chkShowInspections.Checked = value;
                chkShowInspections.Enabled = value;
            }
            get { return chkShowInspections.Checked; }
        }

        public bool ShowCustomKml
        {
            get { return chkShowCustomKml.Checked; }   
        }

        public bool IsElectrical()
        {
            return ctrlInspectionFilter.IsElectrical();
        }

        private void btiConfigureMap_Click(object sender, EventArgs e)
        {
            HidePanels();
            panelMaps.Visible = true;
            panelMaps.Dock = DockStyle.Fill;
        }

        private void HidePanels()
        {
            panelMaps.Visible = false;
            panelAssets.Visible = false;
            panelInspectionVisits.Visible = false;
            panelGPS.Visible = false;
            panelBoth.Visible = false;
        }

        private void btiConfigureAssets_Click(object sender, EventArgs e)
        {
            HidePanels();
            panelAssets.Visible = true;
            panelAssets.Dock = DockStyle.Fill;

        }

        private void btiConfigureGps_Click(object sender, EventArgs e)
        {
            HidePanels();
            panelGPS.Visible = true;
            panelGPS.Dock = DockStyle.Fill;
        }

        private void btiConfigureInspection_Click(object sender, EventArgs e)
        {
            HidePanels();
            panelInspectionVisits.Visible = true;
            panelInspectionVisits.Dock = DockStyle.Fill;
        }

        private void btiConfigureBoth_Click(object sender, EventArgs e)
        {
            HidePanels();
            panelBoth.Visible = true;
            panelBoth.Dock = DockStyle.Fill;

        }

        private void chkShowInspections_CheckedChanged(object sender, EventArgs e)
        {
            if (chkShowInspections.Checked)
            {
                this.chkShowAsset.CheckedChanged -= new System.EventHandler(this.chkShowAsset_CheckedChanged);
                chkShowAsset.Checked = false;
                this.chkShowAsset.CheckedChanged += new System.EventHandler(this.chkShowAsset_CheckedChanged);

                this.chkShowVisit.CheckedChanged -= new System.EventHandler(this.chkShowVisit_CheckedChanged);
                chkShowVisit.Checked = false;
                this.chkShowVisit.CheckedChanged += new System.EventHandler(this.chkShowVisit_CheckedChanged);

            }

            
        }

        private void chkShowVisit_CheckedChanged(object sender, EventArgs e)
        {
            if (chkShowVisit.Checked)
            {
                this.chkShowInspections.CheckedChanged -= new System.EventHandler(this.chkShowInspections_CheckedChanged);
                chkShowInspections.Checked = false;
                this.chkShowInspections.CheckedChanged += new System.EventHandler(this.chkShowInspections_CheckedChanged);


                this.chkShowAsset.CheckedChanged -= new System.EventHandler(this.chkShowAsset_CheckedChanged);
                chkShowAsset.Checked = false;
                this.chkShowAsset.CheckedChanged += new System.EventHandler(this.chkShowAsset_CheckedChanged);

            }

            
        }

        private void chkShowAsset_CheckedChanged(object sender, EventArgs e)
        {
            if (chkShowAsset.Checked)
            {
                this.chkShowInspections.CheckedChanged -= new System.EventHandler(this.chkShowInspections_CheckedChanged);
                chkShowInspections.Checked = false;
                this.chkShowInspections.CheckedChanged += new System.EventHandler(this.chkShowInspections_CheckedChanged);

                this.chkShowVisit.CheckedChanged -= new System.EventHandler(this.chkShowVisit_CheckedChanged);
                chkShowVisit.Checked = false;
                this.chkShowVisit.CheckedChanged += new System.EventHandler(this.chkShowVisit_CheckedChanged);

            }

            
        }

        private void chkShowBoth_CheckedChanged(object sender, EventArgs e)
        {
            if (chkShowBoth.Checked)
            {
                this.chkShowInspections.CheckedChanged -= new System.EventHandler(this.chkShowInspections_CheckedChanged);
                chkShowInspections.Checked = true;
                this.chkShowInspections.CheckedChanged += new System.EventHandler(this.chkShowInspections_CheckedChanged);

                this.chkShowVisit.CheckedChanged -= new System.EventHandler(this.chkShowVisit_CheckedChanged);
                chkShowVisit.Checked = true;
                this.chkShowVisit.CheckedChanged += new System.EventHandler(this.chkShowVisit_CheckedChanged);

            }
        }
    }
}
